class TeaController < ApplicationController
  layout "teachers"

  def index
#    session[:teacher_id] = "2"
#    session[:teacher_name] = "安玉琢"
  end

  #  教师录取情况一览
  def choice_process
    @results = Teacher.get_teacher_result
  end

  #  得到导师选择学生的参考信息
  def select_student
    tea_id = session[:teacher_id]
    @student_invites = Choice.get_student_invites(tea_id)
  end

  #  实现导师选择学生的操作
  def accept_student
    stu_id = params[:id]
    co = Choice.find_by_stu_id(stu_id)
    co.tea_status = "同意"
    co.save!
    if co
      s = Student.find(stu_id)
      flash[:notice] = "恭喜您已经录取了 " + s.sname + " 同学"
      redirect_to(:action => 'accepted_details')
    end
  end

  #  实现导师拒绝学生的操作
  def refuse_student
    stu_id = params[:id]
    co = Choice.find_by_stu_id(stu_id)
    co.tea_status = "拒绝"
    if co
      s = Student.find(stu_id)
      flash[:notice] = "您已经拒绝了 " + s.sname + " 同学"
      redirect_to(:action => 'select_student')
    end
  end
  
  #  显示该导师已录取学生的信息
  def accepted_details
    tea_id = session[:teacher_id]
    @details = Choice.tea_choice_details(tea_id)
  end
end
